package net.letcode.core.utils.security.rsa;

import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;

import org.apache.commons.codec.binary.Base64;

/**
 * RSA密钥对，采用BASE64加密密钥字节数组
 * @author ZDF
 * @date 2015年12月19日
 *
 */
public class RsaKey {
	/** 公钥 */
	private String publicKey;
	
	/** 私钥 */
	private String privateKey;

	public RsaKey() {
		super();
	}
	
	public RsaKey(String publicKey, String privateKey) {
		super();
		this.publicKey = publicKey;
		this.privateKey = privateKey;
	}
	
	public RsaKey(RSAPublicKey publicKey, RSAPrivateKey privateKey) {
		super();
		this.publicKey = Base64.encodeBase64String(publicKey.getEncoded());
		this.privateKey = Base64.encodeBase64String(privateKey.getEncoded());
	}

	public String getPublicKey() {
		return publicKey;
	}
	
	public byte[] getPublicKeyBytes() {
		return Base64.decodeBase64(publicKey);
	}

	public void setPublicKey(String publicKey) {
		this.publicKey = publicKey;
	}

	public String getPrivateKey() {
		return privateKey;
	}
	
	public byte[] getPrivateKeyBytes() {
		return Base64.decodeBase64(privateKey);
	}

	public void setPrivateKey(String privateKey) {
		this.privateKey = privateKey;
	}
}
